package com.teng.smartdrawer.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.teng.smartdrawer.R;
import com.teng.smartdrawer.bean.Seek;

import java.util.List;

/**
 * Created by teng on 16/4/6.
 */
public class WordAdapter extends BaseAdapter {

    List<Seek> data;
    Context context;

    public WordAdapter(Context context, List<Seek> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        int ret = 0;

        if (data != null) {
            ret = data.size();
        }

        return ret;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View ret;
        if (convertView != null) {
            ret = convertView;
        }else {
            ret = LayoutInflater.from(context).inflate(R.layout.item_record_word , parent , false);
        }

        ViewHolder holder = (ViewHolder) ret.getTag();
        if (holder == null){
            holder = new ViewHolder();
            holder.record_text = (TextView) ret.findViewById(R.id.record_text);
            ret.setTag(holder);
        }

        holder.record_text.setText(data.get(position).getName());

        return ret;
    }


    private static class ViewHolder{
        public TextView record_text;
    }

}
